/****************************************************
	文件：SchemeToolsExample.cs
	作者：HuskyT
	邮箱：1005240602@qq.com
	日期：2020/9/20 10:57:22
	功能：测试 配置表工具
*****************************************************/

using System;
using System.Text;
using HTUtility;
using UnityEngine;

namespace HTUtility.Example
{
    public class SchemeToolsExample : MonoBehaviour
    {
        //private EquipmentScheme mData;
        private int cnt = 1000;
        private TimerService mTimerSvc;
        private string mTimer1 = "time1";
        private string mTimer2 = "time2";
        private string mTimer3 = "time3";
        private void Start()
        {
            //初始化计时器服务
            mTimerSvc = TimerService.Instance;
            mTimerSvc.Init();
            //订阅（注册）计时器
            mTimerSvc.Subscribe(mTimer1);
            mTimerSvc.Subscribe(mTimer2);
            mTimerSvc.Subscribe(mTimer3);

            //mData = HelperUtil.XmlToObjInEditor<EquipmentScheme>("Assets/HTUtility/9-SchemeTools/Example/Xml/Equipment.xml");
            //mData = HelperUtil.BinaryToObjInEditor<EquipmentScheme>("Assets/HTUtility/9-SchemeTools/Example/Binary/Equipment.bytes");
            CsvHandler csvHandler = SchemeFactory.Instance.CreateCsv("Assets/HTUtility/9-SchemeTools/Example/Csv/Monster.csv");
            csvHandler.ToExcel("Assets/HTUtility/9-SchemeTools/Example/Excel/Monster.xlsx", Encoding.UTF8);
        }
        private void Update()
        {
            if (Input.GetKeyDown(KeyCode.Q))
            {
                //foreach (var item in mData.EquipmentList)
                //{
                //    Debug.Log(item.Id);
                //    Debug.Log(item.Name);
                //    Debug.Log(item.Description);
                //    Debug.Log(item.Quality);
                //    Debug.Log(item.UseLevelLimit);
                //    Debug.Log(item.PropertyID);
                //    Debug.Log(item.StoreID);
                //    Debug.Log(item.CreatureID);
                //}
            }
            if (Input.GetKeyDown(KeyCode.A)) //测试读表速度（Binary）
            {
                mTimerSvc.Begin(mTimer1);
                for (int i = 0; i < cnt; i++)
                {
                    //mData = HelperUtil.BinaryToObjInEditor<EquipmentScheme>("Assets/HTUtility/9-SchemeTools/Example/Binary/Equipment.bytes");
                }
                mTimerSvc.End(mTimer1);
                Debug.Log("bytes : " + mTimerSvc.GetTotalTime(mTimer1));
            }
            if (Input.GetKeyDown(KeyCode.S)) //测试读表速度（Xml）
            {
                mTimerSvc.Begin(mTimer2);
                for (int i = 0; i < cnt; i++)
                {
                    //mData = HelperUtil.XmlToObjInEditor<EquipmentScheme>("Assets/HTUtility/9-SchemeTools/Example/Xml/Equipment.xml");
                }
                mTimerSvc.End(mTimer2);
                Debug.Log("xml : " + mTimerSvc.GetTotalTime(mTimer2));
            }
            if (Input.GetKeyDown(KeyCode.D)) //测试读表速度（Excel）
            {
                ExcelHandler handler = ExcelKits.Instance.Create("Assets/HTUtility/9-SchemeTools/Example/Excel/Equipment.xlsx");
                mTimerSvc.Begin(mTimer3);
                for (int i = 0; i < cnt; i++)
                {
                    //mData = (EquipmentScheme)handler.ToObj();
                }
                mTimerSvc.End(mTimer3);
                Debug.Log("excel : " + mTimerSvc.GetTotalTime(mTimer3));
            }
        }
    }
}
